package com.javasm.activitymgr;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("activity")
public class ActivityController extends BaseController {
    @Resource
    private ActivityService as;
    //根据活动id查看参与活动的商品信息
    @GetMapping("info/{id}")
    public AxiosResult getAllData(@PathVariable  String id){
        Activity byId = as.getById(id);
        return suc(byId);
    }


    @GetMapping
    public TableDatas getAll(Activity a){
        startPage();
        List<Activity> activity = as.list(new QueryWrapper<>(a));
        return new TableDatas(activity);
    }

    @GetMapping("goods/{id}")
    public AxiosResult listActivitiGoods(@PathVariable String id){
        System.out.println("id");
        List<ActivityGoods> activity = as.listActivitiGoods(id);
        return suc(activity);
    }

    @PostMapping
    public AxiosResult addActivity(@RequestBody Activity a){
        if (as.save(a))return AxiosResult.suc();
        return AxiosResult.error();
    }

    //修改活动/商品信息
    @PutMapping("editActivityGoods")
    public AxiosResult editActivityGoods(@RequestBody List<Activity> activityTypes){
//        if (as.editActivityGoods(activityTypes))return AxiosResult.suc();
//        else return AxiosResult.error();
        return null;
    }

    //删除
    @DeleteMapping("deleteGoods")
    public AxiosResult deleteGoods(Integer id, Integer activityId){
//        if (as.deleteGoods(id,activityId))return AxiosResult.suc();
//        return AxiosResult.error();
        return null;
    }



    //删除
    @DeleteMapping("deleteActivity/{id}")
    public AxiosResult deleteBrand(@PathVariable Integer id){
        if (as.removeById(id))return AxiosResult.suc();
        return AxiosResult.error();
    }
}
